package com.hupu.jrs.api.login

import com.hupu.jrs.bean.CookieData
import com.hupu.jrs.components.retrofit.FastJsonConverterFactory
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import rx.Observable
import rx.schedulers.Schedulers

/**
 * Created by Stark.Tony on 2018/3/18.
 */
class CookieApi(mOkHttpClient: OkHttpClient) {
    private val mCookieService: CookieService

    init {
        val retrofit = Retrofit.Builder().addConverterFactory(FastJsonConverterFactory.create())
                .client(mOkHttpClient)
                .baseUrl(BASE_URL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build()
        mCookieService = retrofit.create(CookieService::class.java)
    }

    fun login(userName: String, passWord: String): Observable<CookieData> {
        return mCookieService.login(userName, passWord).subscribeOn(Schedulers.io())
    }

    companion object {

        private val BASE_URL = "http://passport.hupu.com/pc/login/"
    }
}
